<template>
  <div class="crm-page home-page">
    <div class="page-header">开票详情</div>
    <div class="page-content transparent">
      <div class="page-card">
        <div class="card-title">
          <el-button class="back-btn" size="medium" type="text" icon="el-icon-back" @click="goMainBack()">返回</el-button>
        </div>
        <div class="page-card-content">
          <div class="item-title" style="margin-top:20px">
            基本信息
          </div>
          <div class="card-item">
            <el-row :gutter="10">
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">开票申请编号：</span>
                <span class="content">{{ data.no }}</span>
              </el-col>
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">客户名：</span>
                <span class="content">
                  <span class="app-link" @click="gotoMainPage('customer/info',{id:data.customerId})">  {{ data.customerName }}</span>
                </span>
              </el-col>
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">合同编号：</span>
                <span class="content">
                  <span class="app-link" @click="gotoMainPage('contract/info',{id:data.contractId})">  {{ data.contractNo }}</span>
                </span>
              </el-col>
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">申请单状态：</span>
                <span class="content">{{ data.statusText }}</span>
              </el-col>

              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">所有人：</span>
                <span class="content">{{ data.owner }}</span>
              </el-col>
            </el-row>
          </div>
        </div>
      </div>

      <el-row :gutter="20">
        <el-col :xs="24" :sm="24" :md="24" :lg="14" :xl="14">
          <div class="page-card">
            <div class="page-card-content">
              <div class="item-title no-border">
                <el-tabs v-model="activeTabName">
                  <el-tab-pane label="详细信息" name="1" />
                  <el-tab-pane v-if="data.status>1" label="审批流程" name="3" />
                </el-tabs>
              </div>
              <div v-if="activeTabName==='1'" class="card-item">
                <el-row :gutter="10">
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">客户名：</span>
                    <span class="content">{{ data.customerName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">所有人：</span>
                    <span class="content">{{ data.owner }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">合同编号：</span>
                    <span class="content">{{ data.customerName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">项目/订单编号：</span>
                    <span class="content">{{ data.orderNo }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">开票地址：</span>
                    <span class="content">{{ data.addressText }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">开票日期：</span>
                    <span class="content">{{ data.date| dateFormat('YYYY-MM-DD') }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">开票金额(元)：</span>
                    <span class="content">{{ data.amount | moneyFormat }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">开票类型：</span>
                    <span class="content">{{ data.typeText }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">抬头类型：</span>
                    <span class="content">
                      {{ data.riseType===1?'单位':'个人' }}
                    </span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">纳税识别码：</span>
                    <span class="content">{{ data.identifyCode }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">开票抬头：</span>
                    <span class="content">{{ data.rise }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">开户行：</span>
                    <span class="content">{{ data.bank }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">开户账号：</span>
                    <span class="content">{{ data.account }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">联系人：</span>
                    <span class="content">{{ data.contacts }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">联系方式：</span>
                    <span class="content">{{ data.contactsMode }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                    <span class="title">备注：</span>
                    <span class="content">{{ data.remark }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">创建人：</span>
                    <span class="content">{{ data.createName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">上次修改人：</span>
                    <span class="content">{{ data.updateName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">创建时间：</span>
                    <span class="content">{{ formatTime(data.createTime) }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">上次修改时间：</span>
                    <span class="content">{{ formatTime(data.updateTime) }}</span>
                  </el-col>
                </el-row>
              </div>
              <div v-if="activeTabName==='3'" class="card-item">
                <div class="approve-status">
                  <span>状态：{{ data.statusText }}</span>
                </div>
                <ApproveProcess type="11" :ext-id="data.id" />
              </div>
            </div>
          </div>

        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="10" :xl="10">
          <ActivityCard
            :data="{
              name:data.customerName,
              relateName:data.no,
              relateId:data.id
            }"
            :type="11"
            @change="handleCardChange"
          />
          <ActivityListCard v-if="data.id" ref="listCard" :relateid="data.id" :type="11" />
        </el-col>

      </el-row>

    </div>
  </div>
</template>
<script>
import ActivityCard from '@/components/ActivityCard'
import ActivityListCard from '@/components/ActivityListCard'
import ApproveProcess from '@/components/Approve/ApproveProcess'

import { getInvoice } from '@/api/invoice'

import { getEnumText, invoiceStatus, invoiceTypes } from '@/utils/enums'
import { formatTime } from '@/utils/tools'

export default {
  name: 'CustomerInfo',
  components: { ActivityCard, ActivityListCard, ApproveProcess },
  data() {
    return {
      activeTabName: '1',
      data: {

      }

    }
  },
  mounted() {
    const id = this.$route.query.id
    getInvoice({ id }).then(res => {
      this.data = res
      this.data.statusText = getEnumText(invoiceStatus, this.data.status)
      // typeText
      this.data.typeText = getEnumText(invoiceTypes, this.data.type)
      // 地址展示判断
      if (this.data.address) {
        this.data.addressText = `${this.data.address.province}${this.data.address.city}${this.data.address.county}${this.data.address.address}`
      }
    })
  },
  methods: {
    formatTime,
    handleCardChange() {
      this.$refs.listCard.refresh()
    }

  }
}
</script>

